<?php

	class mysql_follow {


		public  $link = NULL;
		public  $host = NULL;	
		public  $db   = NULL;
		private $user = NULL;
		private $pass = NULL;


		function __construct () {

			$argv = NULL;

			$argv = func_get_args();

			$this -> connect ($argv[0],$argv[1],$argv[2],$argv[3]);

		}


		private function connect ($host,$user,$pass,$db) {

			$this -> link = mysql_connect ($host,$user,$pass);

			mysql_select_db ($db);

		}


		public function show_tables () {

			$tables = NULL;
			
			$query  = 'SHOW TABLES';

			$result = mysql_query ($query);


			while ($row = mysql_fetch_row ($result))

				$tables[] = $row[0];

			return ($tables);

		}

		public function mysql_follow ($field) {
		
				$tables  = NULL;
				$desc    = NULL;
				$matches = array ();

				$tables = $this -> show_tables ();

				foreach ($tables as $tbl) {

					$desc = $this -> desc ($tbl);

					if (in_array ($field,$desc))
						$matches[$tbl] = $this -> column_max_id ($field,$tbl);

				}

			var_dump ($matches);

		}


		public function column_max_id ($field,$table) {

			$query  = 'SELECT MAX(' . $field . ')' . ' ' . 'FROM' . ' ' .$table; 

			$result = mysql_query ($query);

			return (mysql_fetch_array ($result,MYSQL_ASSOC));

		}


		public function desc ($table) {

			$query  = 'DESCRIBE ' . $table;	
			$result = mysql_query ($query);
			$desc   = mysql_fetch_array ($result,MYSQL_ASSOC);

			return ($desc);
			
		}
	

	}

?>
